#!/bin/bash

# 获取参数（第一个参数）
OUTPUT_TO_STDOUT=$1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/opencv3.4.3/lib/
function launch_cam_up {
    cd /opt/ros/noetic/
    source setup.bash
    export ROSCONSOLE_STDOUT_LINE_BUFFERED=1

    if [ "$OUTPUT_TO_STDOUT" == "1" ]; then
        roslaunch usb_cam myusb_cam-test.launch
    else
        roslaunch usb_cam myusb_cam-test.launch >> /userdata/log/usb_cam.log 2>&1
    fi
}

function launch_rtsp_up {
    cd /opt/ros/noetic/
    source setup.bash
    export ROSCONSOLE_STDOUT_LINE_BUFFERED=1

    if [ "$OUTPUT_TO_STDOUT" == "1" ]; then
        roslaunch ros_rtsp cam_rtsp.launch
    else
        roslaunch ros_rtsp cam_rtsp.launch >> /userdata/log/ros_rtsp.log 2>&1
    fi
}

function launch_cam_manager_up {
    cd /opt/ros/noetic/
    source setup.bash
    export ROSCONSOLE_STDOUT_LINE_BUFFERED=1
    if [ "$OUTPUT_TO_STDOUT" == "1" ]; then
        rosrun ros_cam_manager ros_cam_manager >> /userdata/log/ros_cam.log 2>&1
    else
        rosrun ros_cam_manager ros_cam_manager >> /userdata/log/ros_cam.log 2>&1
    fi
}

function launch_allnodes_up {
    cd /opt/ros/noetic/
    source setup.bash
    export ROSCONSOLE_STDOUT_LINE_BUFFERED=1

    if [ "$OUTPUT_TO_STDOUT" == "1" ]; then
        roslaunch ros_rtsp all_nodes.launch
    else
        roslaunch ros_rtsp all_nodes.launch >> /userdata/log/all_nodes.log 2>&1
    fi
}


mkdir -p /userdata/log

# 后台启动各模块
#launch_cam_up &

#sleep 1

#launch_rtsp_up &

launch_allnodes_up &

sleep 1

#与降落程序冲突
#launch_cam_manager_up &
